# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=mypaint-brushes
_realver=1.3.0
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=${_realver/-/}
pkgrel=1
pkgdesc="Brush engine used by MyPaint (mingw-w64)"
arch=('any')
url="https://github.com/Jehan/mypaint-brushes"
license=("ISC")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-libmypaint")
options=('strip' '!debug')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/Jehan/mypaint-brushes/archive/v${pkgver}.tar.gz
        001-fix-pkgdir-location.patch)
sha256sums=('704bb6420e65085acfd7a61d6050e96b0395c5eab078433f11406c355f16b214'
            '45894c60fe9e9dcd0bcf8ad3b5f6acf90651a6196058ad80c1052533b2d23b12')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true

  cd ${_realname}-${_realver}
  patch -p1 -i ${srcdir}/001-fix-pkgdir-location.patch
  ./autogen.sh
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/share/pkgconfig" \
  ../${_realname}-${_realver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make -j1 DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${_realver}/Licenses.md "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/Licenses.md
}
